import * as TYPE from './type';
import {toGet, toPost} from '../../utils/MyAxios';
import {Notice} from 'iview';

/*获取报表管理信息列表*/
export const getReportList = ({commit},params) => {
  toGet('/finance-management/finance/expense/queryAll/'+JSON.stringify(params))
    .then((response) => {
      if (response.resultCode === 0) {
        let responseData=response.data;
        commit(TYPE.REPORT, {
          list:responseData.list,
          total:responseData.total,
          currentPage:responseData.currentPage,
          pageSize:responseData.pageSize,
        });
      }
      else {
        Notice.error({
          title: '获取汇总表列表失败',
          desc: response.resultMsg
        });
      }
    });
};

/*获取资金单据列表*/
export const getReceiptList = ({commit},params) => {
  toGet('/finance-management/finance/receipt/queryAll/'+JSON.stringify(params))
    .then((response) => {
      if (response.resultCode === 0) {
        let responseData=response.data;
        commit(TYPE.RECEIPT, {
          list:responseData.list,
          total:responseData.total,
          currentPage:responseData.currentPage,
          pageSize:responseData.pageSize,
        });
      }
      else {
        Notice.error({
          title: '获取资金单据失败',
          desc: response.resultMsg
        });
      }
    });
};

/*获取货物列表*/
export const getGoodsList = ({commit},params) => {
  toGet('/finance-management/finance/goods/queryAll/'+JSON.stringify(params))
    .then((response) => {
      if (response.resultCode === 0) {
        let responseData=response.data;
        commit(TYPE.GOODS, {
          list:responseData.list,
          total:responseData.total,
          currentPage:responseData.currentPage,
          pageSize:responseData.pageSize,
        });
      }
      else {
        Notice.error({
          title: '获取货物失败',
          desc: response.resultMsg
        });
      }
    });
};

/*获取库存记录列表*/
export const getGoodsRecordList = ({commit},params) => {
  toGet('/finance-management/finance/record/queryAll/'+JSON.stringify(params))
    .then((response) => {
      if (response.resultCode === 0) {
        let responseData=response.data;
        commit(TYPE.GOODSRECORD, {
          list:responseData.list,
          total:responseData.total,
          currentPage:responseData.currentPage,
          pageSize:responseData.pageSize,
        });
      }
      else {
        Notice.error({
          title: '获取库存记录失败',
          desc: response.resultMsg
        });
      }
    });
};

/*获取项目记录列表*/
export const getProjectList = ({commit},params) => {
  toGet('/finance-management/finance/project/queryAll/'+JSON.stringify(params))
    .then((response) => {
      if (response.resultCode === 0) {
        let responseData=response.data;
        commit(TYPE.PROJECT, {
          list:responseData.list,
          total:responseData.total,
          currentPage:responseData.currentPage,
          pageSize:responseData.pageSize,
        });
      }
      else {
        Notice.error({
          title: '获取项目列表失败',
          desc: response.resultMsg
        });
      }
    });
};


/*获取工作核算记录列表*/
export const getWagesList = ({commit},params) => {
  toGet('/finance-management/finance/wages/queryAll/'+JSON.stringify(params))
    .then((response) => {
      if (response.resultCode === 0) {
        let responseData=response.data;
        commit(TYPE.WAGES, {
          list:responseData.list,
          total:responseData.total,
          currentPage:responseData.currentPage,
          pageSize:responseData.pageSize,
        });
      }
      else {
        Notice.error({
          title: '获取工作核算列表失败',
          desc: response.resultMsg
        });
      }
    });
};

